﻿<template>
	<div class="patCell-container">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form :model="queryParams" ref="queryForm" :inline="true">
			<el-row :gutter="35">
              <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
              <el-form-item label="托盘号">
              <el-input v-model="queryParams.trayID" clearable placeholder="请输入托盘号"/>
              </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
              <el-form-item label="电芯号">
              <el-input v-model="queryParams.cellID" clearable placeholder="请输入电芯号"/>
              </el-form-item>
              </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20 search-actions">
		
          <div>
			

			<el-button type="primary"  @click="pushRemoteCell" v-auth="'patCell:push'"> 请求组装电芯 </el-button>

		<el-button type="primary"  @click="patToFms" v-auth="'patCell:push'"> 推送FMS </el-button>

		<el-button type="primary" icon="ele-Plus" @click="openAddPatCell" v-auth="'patCell:add'"> 新增 </el-button>







  


    <el-button @click="openUploadDialog" v-auth="'patCell:push'" type="primary">上传</el-button>

    <el-button @click="Export" v-auth="'patCell:push'" type="primary">导出</el-button>
		
		</div>
          <div>
          <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>
          <el-button type="primary" plain icon="ele-Search" @click="handleQuery" v-auth="'patCell:page'"> 查询 </el-button>
          </div>
          </el-col>
      </el-row>
      </el-form>
		</el-card>
		<el-card shadow="hover" style="margin-top: 8px">
			<el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
				row-key="id"
				border="">
				<el-table-column type="index" label="序号" width="55" align="center" fixed="" />
				 <el-table-column prop="pline" label="线体" fixed="" show-overflow-tooltip="" />
				 <el-table-column prop="modeL_NO" label="型号" fixed="" show-overflow-tooltip="" />
				 <el-table-column prop="loT_NO" label="批次号" fixed="" show-overflow-tooltip="" />
				 <el-table-column prop="trayid" label="托盘号" fixed="" show-overflow-tooltip="" />
				 <el-table-column prop="channel" label="通道号" fixed="" show-overflow-tooltip="" />
				 <el-table-column prop="cellid" label="电芯号" fixed="" show-overflow-tooltip="" />
				 <el-table-column prop="ir" label="电阻" fixed="" show-overflow-tooltip="" />
				 <el-table-column prop="ocv" label="电压" fixed="" show-overflow-tooltip="" />
				 <el-table-column prop="date_Time" label="时间" fixed="" show-overflow-tooltip="" />
				 <el-table-column prop="message" label="信息" fixed="" show-overflow-tooltip="" />
				<el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('patCell:edit') || auth('patCell:delete')">
					<template #default="scope">
						<el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditPatCell(scope.row)" v-auth="'patCell:edit'"> 编辑 </el-button>
						<el-button icon="ele-Delete" size="small" text="" type="primary" @click="delPatCell(scope.row)" v-auth="'patCell:delete'"> 删除 </el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100]"
				small=""
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
	/>
			<editDialog
			    ref="editDialogRef"
			    :title="editPatCellTitle"
			    @reloadTable="handleQuery"
      />
	  <patPushDialog
			    ref="patDialogRef"
			    
			    @reloadTable="handleQuery"
      />
		</el-card>

    
<el-dialog v-model="state.dialogVisible" :lock-scroll="false" draggable width="400px">
			<template #header>
				<div style="color: #fff">
					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-UploadFilled /> </el-icon>
					<span> 上传文件 </span>
				</div>
			</template>
			<div style="text-align: center;">
       
          <el-upload :headers="headers"  ref="uploadRef" multiple drag :auto-upload="false" :limit="3" :file-list="state.fileList" action="" :on-change="handleChange" accept=".xlsx">
					<el-icon class="el-icon--upload">
						<ele-UploadFilled />
					</el-icon>
					<div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
					<template #tip>
						<div class="el-upload__tip">请上传大小不超过 10MB 的文件 </div>
            
					</template>
				</el-upload>
    

        <div>
        <el-button  @click="download" class="el-upload__tip">模板下载</el-button>
      </div>  
        
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="state.dialogVisible = false">取消</el-button>
					<el-button type="primary" @click="uploadFile">确定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>


</template>

<script lang="ts" setup>
	import { ref,reactive } from "vue";
	import { ElMessageBox, ElMessage,UploadUserFile,UploadProps } from "element-plus";
	import { auth } from '/@/utils/authFunction';
	//import { formatDate } from '/@/utils/formatTime';

	import editDialog from '/@/views/main/patCell/component/editDialog.vue'

	import patPushDialog from '/@/views/main/patCell/component/patPushDialog.vue'
	import { getPatCellPageList, deletePatCell,PushToFms,Upload,Template,ExportData } from '/@/api/main/patCell';



		const editDialogRef = ref();
		const patDialogRef = ref();
		const loading = ref(false);
		const tableData = ref<any>([]);
const queryParams = ref<any>
	({});
	const tableParams = ref({
	page: 1,
	pageSize: 10,
	total: 0,
	});
	const editPatCellTitle = ref("");


	// 查询操作
	const handleQuery = async () => {
	loading.value = true;
	var res = await getPatCellPageList(Object.assign(queryParams.value, tableParams.value));
	tableData.value = res.data.result?.items ?? [];
	tableParams.value.total = res.data.result?.total;
	loading.value = false;
};

// 打开新增页面
const openAddPatCell = () => {
	editPatCellTitle.value = '添加';
  editDialogRef.value.openDialog({});
};

// 打开编辑页面
const openEditPatCell = (row: any) => {
	editPatCellTitle.value = '编辑';
  editDialogRef.value.openDialog(row);
};
// 推送组装电芯
const pushRemoteCell=()=>{
   patDialogRef.value.openDialog({
	  contractTag:200
   })
};

// 推送FMS
const patToFms=async()=>{
   await PushToFms();
   ElMessage.success("推送成功");
};

// 删除
const delPatCell = (row: any) => {
  ElMessageBox.confirm(`确定要删除吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
	    await deletePatCell(row);
      handleQuery();
      ElMessage.success("删除成功");
    })
    .catch(() => {});
};

// 改变页面容量
const handleSizeChange = (val: number) => {
  tableParams.value.pageSize = val;
  handleQuery();
};

// 改变页码序号
const handleCurrentChange = (val: number) => {
  tableParams.value.page = val;
  handleQuery();
};


handleQuery();







  const state = reactive({
	dialogVisible: false,
	fileList: [] as any[],
});

// 打开上传页面
const openUploadDialog = () => {
	state.fileList = [];
	state.dialogVisible = true;
};

// 通过onChanne方法获得文件列表
const handleChange = (file: any, fileList: []) => {
	state.fileList = fileList;
};

 // 设置请求头
 const headers = {
    'Content-Type': 'multipart/form-data'
  }
  
// 上传
const uploadFile = async () => {
	if (state.fileList.length < 1) return;

  let param = new FormData()

  state.fileList.forEach(x => {
    param.append("files", x.raw)
  });

 
  

	await Upload(param);
	handleQuery();
	ElMessage.success('上传成功');
	state.dialogVisible = false;
};
// 下载模板
const download=async()=>{
  
loading.value=true;
 var data= await Template();
loading.value=false;
 window.location.href=import.meta.env.VITE_API_URL+"/"+data.data.result;
  
};
// 导出数据
const Export=async()=>{
  loading.value=true;
  var data= await ExportData();
  loading.value=false;
  window.location.href=import.meta.env.VITE_API_URL+"/"+data.data.result;
   
 };







</script>


